#include "card_table.h"
#include "card_compartor.h"
#include "card_generator.h"

namespace dymy
{
    namespace table
    {
        Person::Person(ID_t id, const std::string &user_name) : user_id(id), user_name(user_name), role(Role::ROLE_FARMER), prepared(false), status(PERSON_STEP_WAITING), played_cards()
        {
        }
        Person::Person() : Person(0, "")
        {
        }
        void Person::FillCards(multiple_card_t &&cards) noexcept
        {
            this->cards = std::move(cards);
        };
        bool Person::delete_in(const std::vector<card_t> &cards)
        {
            multiple_card_t c = this->cards;
            using it = multiple_card_t::iterator;
            auto begin = cards.cbegin();
            it (*find_fun)(it lhs, it rhs, const card_t &v) = [](it lhs, it rhs, const card_t &v) -> it
            {
                return std::find_if(lhs, rhs, [&v](auto &&vv)
                                    { return v == vv; });
            };

            while (begin != cards.cend())
            {
                auto it = find_fun(c.begin(), c.end(), *begin);
                ++begin;

                if (it == c.end())
                {
                    return false;
                }
                else
                {
                    c.erase(it);
                }
            }

            this->cards = std::move(c);
            return true;
        }

        // CardTable::CardTable(uint32_t table_id) : m_table_id(table_id), m_current_table_landlord_index(-1),
        //                                           m_prev_play_max_card_index(-1),
        //                                           m_current_play_max_cards(),
        //                                           m_persons(),
        //                                           m_step(STEP_WATING), hole_cards_()
        // {
        // }

        // void TableMamager::generate_cards(CardTable *ptr)
        // {
        // }

        // int TableMamager::add_person(CardTable *ptr, size_t index, ID_t person_id, const std::string &user_name)
        // {

        // }
        // int TableMamager::remove_person(CardTable *ptr, size_t index, ID_t person_id)
        // {

        // }

        // int TableMamager::prepared(CardTable *ptr, size_t index, ID_t person_id, bool prepared)
        // {

        // }
        // int TableMamager::start(CardTable *ptr)
        // {

        // }
        // int TableMamager::rob_landlord(CardTable *ptr, size_t index, ID_t person_id, bool rob)
        // {

        // }
        // int TableMamager::play_cards(CardTable *ptr, size_t index, ID_t person_id, const std::vector<uint8_t> &cards)
        // {

        // }

        // int TableMamager::play_cards_internal(CardTable *ptr, size_t index, PersonPtr p, const std::vector<card_t> &cards)
        // {

        // }

        // void TableMamager::release(CardTable *ptr, bool clear_cards)
        // {

        // }
        // void TableMamager::stop(CardTable *ptr)
        // {

        // }
    }

}